﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace welwitschia.Administracao
{
    public partial class RoleLista : PaginaBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataBindList();
        }

        protected void Unnamed1_Click(object sender, EventArgs e)
        {
            Response.Redirect(@"~\Administracao\RoleDetalhe.aspx");
        }

        protected void lvGrupoUtilizadores_ItemDeleting(object sender, ListViewDeleteEventArgs e)
        {
        }

        protected void lvGrupoUtilizadores_ItemEditing(object sender, ListViewEditEventArgs e)
        {
        }

        protected void lvGrupoUtilizadores_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            try
            {
                if (e.CommandName == "Edit")
                    Response.Redirect(@"~\Administracao\RoleDetalhe.aspx?r=" + e.CommandArgument.ToString());
                else if (e.CommandName == "Delete")
                {
                    Roles.DeleteRole(e.CommandArgument.ToString());
                    DataBindList();
                }
            }
            catch (Exception ex)
            {
                MostraErro(ex.Message);   
            }
        }

        private void DataBindList()
        {
            lvGrupoUtilizadores.DataSource = Roles.GetAllRoles();
            lvGrupoUtilizadores.DataBind(); 
        }
    }
}